package com.yuneec.droneservice.command;

import com.yuneec.droneservice.model.JoystickMap;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetJoystickMap extends BaseCommand {

    public GetJoystickMap() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_CH_MAP);
    }

    @Override
    public IResponse<JoystickMap> toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<JoystickMap> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            JoystickMap joystickMap = new JoystickMap();
            joystickMap.setCh1(data[off + 2] & 0xff);
            joystickMap.setCh2(data[off + 3] & 0xff);
            joystickMap.setCh3(data[off + 4] & 0xff);
            joystickMap.setCh4(data[off + 5] & 0xff);
            response.setParam(joystickMap);
        }
        return response;
    }

}
